package com.tduck.cloud.api.web.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tduck.cloud.common.util.QueryWrapperUtils;
import com.tduck.cloud.common.util.Result;
import com.tduck.cloud.form.entity.FormScoreEntity;
import com.tduck.cloud.form.request.RelationshipRequest;
import com.tduck.cloud.form.service.FormScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/form/score")
public class FormScoreController {
    @Autowired
    private FormScoreService formScoreService;
    @GetMapping("/list")
    public Result<Page<FormScoreEntity>> list(Page<FormScoreEntity> page, RelationshipRequest request){
        QueryWrapper<FormScoreEntity> simpleQuery = QueryWrapperUtils.toSimpleQuery(BeanUtil.copyProperties(request, FormScoreEntity.class));
        simpleQuery.orderByDesc("create_time");
        return Result.success(formScoreService.page(page, simpleQuery));
    }
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody @Validated FormScoreEntity formScore){
        return Result.success(formScoreService.save(formScore));
    }

    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody @Validated FormScoreEntity formScore){
        return Result.success(formScoreService.updateById(formScore));
    }

    @PostMapping("/delete")
    public Result<Boolean> delete(Long id){
        return Result.success(formScoreService.removeById(id));
    }

}
